package com.dgut.demo.controller;

import com.dgut.demo.bean.SupplierMessage;
import com.dgut.demo.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/2/4 23:14
 * @Version 1.0
 */
@RestController
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    @GetMapping("/getAllSupplierMessage")
    public List<SupplierMessage> getAllSupplierMessage(){
        return supplierService.getAllSupplierMessage();
    }

    @PostMapping("/addOneSupplierMessage")
    public int addOneSupplierMessage(String sphone, String sname, String smaterial, double sprice, String saddress, Date sendtime){
        SupplierMessage supplierMessage = new SupplierMessage();
        supplierMessage.setSaddress(saddress);
        supplierMessage.setSmaterial(smaterial);
        supplierMessage.setSname(sname);
        supplierMessage.setSendtime(sendtime);
        supplierMessage.setSphone(sphone);
        supplierMessage.setSprice(sprice);
        return supplierService.addOneSupplierMessage(supplierMessage);
    }

    @DeleteMapping("/deleteOneSupplierMessage")
    public int deleteOneSupplierMessage(String sid){
        return supplierService.deleteOneSupplierMessage(sid);
    }

    @PutMapping("/updateOneSupplierMessage")
    public int updateOneSupplierMessage(String sid,String sphone, String sname, String saddress){
        SupplierMessage supplierMessage = new SupplierMessage();
        supplierMessage.setSaddress(saddress);
        supplierMessage.setSid(sid);
        supplierMessage.setSname(sname);
        supplierMessage.setSphone(sphone);
        return supplierService.updateOneSupplierMessage(supplierMessage);
    }

    @GetMapping("/getSupplierMessageById")
    public List<SupplierMessage> getSupplierMessageById(String sid){
        return supplierService.getSupplierMessageById(sid);
    }

    @GetMapping("/getSupplierMessageByName")
    public List<SupplierMessage> getSupplierMessageByName(String sname){
        return supplierService.getSupplierMessageByName(sname);
    }

    @GetMapping("/getSupplierMessageByPhone")
    public List<SupplierMessage> getSupplierMessageByPhone(String sphone){
        return supplierService.getSupplierMessageByPhone(sphone);
    }

    @GetMapping("/getSupplierMessageByMaterial")
    public List<SupplierMessage> getSupplierMessageByMaterial(String smaterial){
        return supplierService.getSupplierMessageByMaterial(smaterial);
    }

    @GetMapping("/getSupplierMessageByAddress")
    public List<SupplierMessage> getSupplierMessageByAddress(String saddress){
        return supplierService.getSupplierMessageByAddress(saddress);
    }
}
